﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Configuration;
using System.Text;
using System.Threading.Tasks;
using JBeamLibrary.Tools;
using JBeamLibrary.VehicleParts.Interfaces;
using Newtonsoft.Json.Linq;

namespace JBeamLibrary.VehicleParts.Elements
{
    public class Ropable : VehicleElement
    {
        #region Properties

        public string NodeId { get; set; }

        public string Group { get; set; }

        public bool MultiLock { get; set; }

        #endregion

        #region CTORs

        public Ropable()
        {

        }

        public Ropable(string nodeId, string group, bool multiLock)
        {
            NodeId = nodeId;
            Group = group;
            MultiLock = multiLock;
        }

        #endregion

        #region Methods

        public override IVehicleElement FromJBeam(JToken token)
        {
            var arr = token as JArray;
            if (arr == null) return this;

            NodeId = token[0].FromJBeam<string>();
            Group = token[1].FromJBeam<string>();
            MultiLock = token[2].FromJBeam<bool>();

            return this;
        }

        public override JToken ToJBeam()
        {
            return new JArray
            {
                NodeId,
                Group,
                MultiLock
            };
        }

        public override string ToString()
        {
            return string.Format("[node:{0}, group:{1}, multilock:{2}]", NodeId, Group, MultiLock);
        }

        #endregion
    }
}
